package com.koron.order.risk.base.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.base.bean.po.LineRiskPart;
import com.koron.order.risk.base.mapper.LineRiskPartMapper;
import com.koron.order.risk.base.service.LineRiskPartService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 风险管控单-塔段(LineRiskPart)表服务实现类
 *
 * @author jzp
 * @since 2022-12-15 16:18:00
 */
@Service
public class LineRiskPartServiceImpl implements LineRiskPartService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineRiskPart getById(SessionFactory factory, String id) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineRiskPart> list(SessionFactory factory, LineRiskPart lineRiskPart) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.selectList(lineRiskPart);
    }

    @Override
    @TaskAnnotation("listByRiskId")
    public List<LineRiskPart> listByRiskId(SessionFactory factory, String riskId) {
        LineRiskPart lineRiskPart = new LineRiskPart();
        lineRiskPart.setRiskId(riskId);
        return list(factory, lineRiskPart);
    }

    @Override
    @TaskAnnotation("listByRiskIds")
    public List<LineRiskPart> listByRiskIds(SessionFactory factory, List<String> riskIds) {
        if (CollUtil.isEmpty(riskIds)) {
            return null;
        }
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.selectListByRiskIds(riskIds);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineRiskPart lineRiskPart) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.insertOrUpdate(lineRiskPart) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LineRiskPart> list) {
        if (CollUtil.isEmpty(list)) {
            return false;
        }
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.insertOrUpdateBatch(list) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineRiskPart lineRiskPart) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.update(lineRiskPart) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByRiskId")
    public boolean removeByRiskId(SessionFactory factory, String id) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.removeByRiskId(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByRiskIds")
    public boolean removeByRiskIds(SessionFactory factory, List<String> riskIds) {
        LineRiskPartMapper mapper = factory.getMapper(LineRiskPartMapper.class);
        return mapper.removeByRiskIds(riskIds) > 0;
    }
}
